import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'

export const asyncRoutes = [
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '/home',
        component: () => import( /*webpackChunkName:"home" */ '../src/views/home/home.vue'),
        meta: {
            isShowNav: true,
            til: "首页"
        }
    },
    {
        path: '/categary',
        component: () => import( /*webpackChunkName:"categary" */ '../src/views/categary/categary.vue'),
        meta: {
            isShowNav: true
        }
    },
    {
        path: '/cart',
        component: () => import( /*webpackChunkName:"cart" */ '../src/views/cart/cart.vue'),
        meta: {
            isShowNav: true
        }
    },
    {
        path: '/user',
        component: () => import( /*webpackChunkName:"user" */ '../src/views/user/user.vue'),
        meta: {
            isShowNav: true
        }
    },
    {
        path: '/login',
        component: () => import( /*webpackChunkName:"login" */ '../src/views/login/login.vue'),
        meta: {
            isShowNav: false
        }
    },
    


]

const router = createRouter({
    history: createWebHashHistory(),  // 带#的hash路由模式
    // history: createWebHistory(),         // 不带#的history路由模式
    routes: [
        ...asyncRoutes,
        { path: '/*', redirect: '/' }     // 重定向
    ]
})

router.beforeEach((to, from, next) => {
    document.title = to.meta.til || "mlyx"
    next()
})

export default router